package com.bbu.javaexam.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bbu.javaexam.domain.JudgeQuestion;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Alex
 * @version 1.0.0
 * @ClassName JudgeQuestionMapper.java
 * @Description TODO
 */
@Mapper
public interface JudgeQuestionMapper extends BaseMapper<JudgeQuestion> {
    /**
     * @throws
     * @title 查询paperId所支持的题目
     * @description
     * @author Alex
     * @updateTime 2021/12/5 14:44
     */
    @Select("select * from judge_question where questionId in (select questionId from paper_manage where questionType = 3 and paperId = #{paperId})")
    List<JudgeQuestion> findByIdAndType(Integer paperId);

    /**
     * @throws
     * @title 通过分页查询所有题目
     * @description
     * @author Alex
     * @updateTime 2021/12/5 14:45
     */
    @Select("select * from judge_question")
    IPage<JudgeQuestion> findAll(Page page);

    /**
     * @throws
     * @title查询最后一t条ID
     * @description
     * @author Alex
     * @updateTime 2021/12/5 14:44
     */
    @Select("select questionId from judge_question order by questionId desc limit 1")
    JudgeQuestion findOnlyQuestionId();

    /**
     * @throws
     * @title 新增一题判断题
     * @description
     * @author Alex
     * @updateTime 2021/12/5 14:47
     */
    @Insert("insert into judge_question(subject,question,answer,analysis,level,section) values " +
            "(#{subject},#{question},#{answer},#{analysis},#{level},#{section})")
    int add(JudgeQuestion judgeQuestion);

    /**
     * @throws
     * @title 通过科目查找判断题
     * @description
     * @author Alex
     * @updateTime 2021/12/5 14:47
     */
    @Select("select questionId from judge_question  where subject=#{subject}  order by rand() desc limit #{pageNo}")
    List<Integer> findBySubject(String subject, Integer pageNo);
}
